package com.domain.factory;

import com.domain.DO.FlightClass;
import com.domain.DO.FlightInfo;
import com.domain.DO.FlightOrder;
import com.domain.DTO.FlightOrderDto;
import com.domain.VO.FlightOrderVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.BeanUtils;

/**
 * @author 大忽悠
 * @create 2022/11/11 18:09
 */
public class FlightOrderFactory {
    public static final FlightOrderConvert FLIGHT_ORDER_CONVERT = Mappers.getMapper(FlightOrderConvert.class);

    @Mapper
    public interface FlightOrderConvert {
        @Mappings({
                @Mapping(target = "id", ignore = true),
                @Mapping(target = "seat",ignore = true)
        })
        FlightOrder toFlightOrder(FlightOrderVo flightOrderVo);

        default FlightOrderDto toFlightOrderDto(FlightOrder flightOrder, FlightClass flightClass, FlightInfo flightInfo) {
            FlightOrderDto flightOrderDto = new FlightOrderDto();
            BeanUtils.copyProperties(flightOrder, flightOrderDto);
            BeanUtils.copyProperties(flightClass, flightOrderDto);
            BeanUtils.copyProperties(flightInfo, flightOrderDto);
            return flightOrderDto;
        }

        ;
    }
}
